package com.jcw.kqxt.constants;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 自定义异常类
 */
public class ResolveException extends RuntimeException {

    private static final Logger logger = LoggerFactory.getLogger(ResolveException.class);


    private int code;


    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public ResolveException(){}


    public ResolveException(com.jcw.kqxt.constants.ErrorCodeInterface resultCode) {
        super(resultCode.getMessage());
        this.code = resultCode.getCode();
    }

    public ResolveException(com.jcw.kqxt.constants.ErrorCodeInterface resultCode, Throwable cause) {
        super(resultCode.getMessage(), cause);
        this.code = resultCode.getCode();
    }

    @Deprecated
    public ResolveException(int code, Throwable cause) {
        super(cause);
        this.code = code;
    }

    @Deprecated
    public ResolveException(String msg) {
        super(msg);
        this.code = com.jcw.kqxt.constants.ErrorUserOperEnum.UNKNOWN_ERROR.getCode();
    }

    @Deprecated
    public ResolveException(int code,String message) {
        super(message);
        this.code = code;
    }

    public static void printException(Object object){
        Exception exception = (Exception) object;
        exception.printStackTrace();
        StackTraceElement[] elements = exception.getStackTrace();
        logger.error("error message:{}",exception.getMessage());
        logger.error("Caused by:",exception.getCause());
        for(StackTraceElement element:elements){
            String string = element.toString();
            logger.error("   at {}",string);
        }
    }


}
